package com.springboot.demo.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;
/**
 * Created by byzhang on 2018-5-27
 */
@Repository
public class RedisDao {

    @Autowired
    private StringRedisTemplate template;
    public void setKey(String key, String value){
        ValueOperations<String, String> ops = template.opsForValue();
        ops.set(key, value , 10 , TimeUnit.MINUTES);
    }

    public String getValue(String key){
        ValueOperations<String, String> ops = this.template.opsForValue();
        return ops.get(key);
    }

    public boolean hasKey(String key){
        return template.hasKey(key);
    }
}
